<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>假果酱后台</title>
    <link href="/tencent/css/bootstrap.min.css" rel="stylesheet">
    <link href="/tencent/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="/tencent/css/animate.css" rel="stylesheet">
    <link href="/tencent/css/style.css" rel="stylesheet">
</head>
<body>
    <div id="wrapper">

        <nav class="navbar-default navbar-static-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav metismenu" id="side-menu">
                    <li class="nav-header">
                        <div class="dropdown profile-element"> <span>
                            <img alt="image" class="img-circle" src="/tencent/img/logo1.png" width="48px" height="48px"/>
                             </span>
                            <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">欢迎大佬</strong>
                             </span> <span class="text-muted text-xs block">常用操作 <b class="caret"></b></span> </span> </a>
                            <ul class="dropdown-menu animated fadeInRight m-t-xs">
                                <li><a href="/tencent/fireIndex/index">返回首页</a></li>
                                <li><a href="/tencent/fireIndex/lookAllUser">查看所有用户信息</a></li>
                                <li><a href="">你看不见我</a></li>
                                <li class="divider"></li>
                                <li><a href="/tencent/fireIndex/login">Logout</a></li>
                            </ul>
                        </div>
                        <div class="logo-element">
                            IN+
                        </div>
                    </li>
                    <li class="active">
                        <a href="/tencent/fireIndex/index"><i class="fa fa-database"></i> <span class="nav-label">功能模块</span> <span class="fa arrow"></span></a>
                        <ul class="nav nav-second-level collapse">
                            <li><a href="/tencent/fireIndex/index"><i class="fa fa-th-large"></i>主页</a></li>
                            <li><a href="/tencent/fireIndex/basic_gallery"><i class="fa fa-picture-o"></i>画廊</a></li>
                            <li><a href="/tencent/fireIndex/lookAllUser"><i class="fa fa-star"></i>用户信息</a></li>
                            <li class="active"><a href="/tencent/fireIndex/pin_board"><i class="fa fa-edit"></i>公告</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </nav>

        <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
                    <form role="search" class="navbar-form-custom" action="search_results.html">
                        <div class="form-group">
                            <input type="text" placeholder="Search for something..." class="form-control" name="top-search" id="top-search">
                        </div>
                    </form>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li>
                        <span class="m-r-sm text-muted welcome-message">欢迎进入假果酱后台</span>
                    </li>



                    <li>
                        <a href="/tencent/fireIndex/login">
                            <i class="fa fa-sign-out"></i> Log out
                        </a>
                    </li>
                </ul>

            </nav>
        </div>
            <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-9">
                    <h2>公告</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.html">主页</a>
                        </li>
                        <li>
                           公告栏
                        </li>
                        <li class="active">
                            <strong>Notice</strong>/&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-primary btn-sm" onclick="alertModel(0)">新建公告</button>
                        </li>
                    </ol>
                </div>
            </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="wrapper wrapper-content animated fadeInUp">
                    <ul class="notes" id="notices">
                    </ul>
                </div>
            </div>
        </div>
        <div class="footer">
            <div class="pull-right">
                Copyright @假果酱
            </div>
            <div>
                © 2018 - no money pay for aliyun
            </div>
        </div>

        </div>
        </div>

    <!-- Mainly scripts -->
    <script src="/tencent/js/jquery-2.1.1.js"></script>
    <script src="/tencent/js/bootstrap.min.js"></script>
    <script src="/tencent/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="/tencent/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <!-- Custom and plugin javascript -->
    <script src="/tencent/js/inspinia.js"></script>
    <script src="/tencent/js/plugins/pace/pace.min.js"></script>


</body>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                   公告编辑
                </h4>
            </div>
            <div class="modal-body" id="resultJson">

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    function formatDate(now) {
        var year = now.getFullYear(),
            month = now.getMonth() + 1,
            date = now.getDate(),
            hour = now.getHours(),
            minute = now.getMinutes(),
            second = now.getSeconds();
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    }
    function type(display) {
        if(display==0){
            return "公开";
        }else{
            return "私密";
        }
    }
    function alertModel(id) {
        if(id==0){
            var content = '<div class="form-group">' +
                '		<label for="name">公告内容</label>' +
                '		<textarea class="form-control" rows="5" id="noticeTextArea">' + '</textarea>' +
                '	</div>' + '	<div class="checkbox">' +
                '		<label>' +
                '			<input type="checkbox" id="isDisplay"> 是否公开' +
                '		</label>' +
                '	</div>' + '<div  style="text-align: right"><button onclick="saveNotice(' + id + ')" class="btn btn-primary">提交</button></div>';
            document.getElementById("resultJson").innerHTML = content;
        }else {
            $.post("/tencent/fire/findByIdNotice", {id: id}, function (data) {
                if (data.code == 0) {

                    var content = '<div class="form-group">' +
                        '		<label for="name">公告内容</label>' +
                        '		<textarea class="form-control" rows="5" id="noticeTextArea">' + data.data.text + '</textarea>' +
                        '	</div>' + '	<div class="checkbox">' +
                        '		<label>' +
                        '			<input type="checkbox" id="isDisplay"> 是否公开' +
                        '		</label>' +
                        '	</div>' + '<div  style="text-align: right"><button onclick="saveNotice(' + id + ')" class="btn btn-primary">提交</button></div>';
                    document.getElementById("resultJson").innerHTML = content;
                }
            });
        }
        $('#myModal').modal({
            keyboard: true
        });
    }
    function saveNotice(id) {
       var noticeTextArea = document.getElementById("noticeTextArea").value;
       var isDisplay = document.getElementById("isDisplay").checked;
        if(id==0) {  //新建
            if (isDisplay == true) {
                isDisplay = "0";
            }else{
                isDisplay = "1";
            }
            $.post("/tencent/fire/saveNotice", {text: noticeTextArea, isDisplay: isDisplay}, function (data) {
                $('#myModal').modal('hide');
                getNotices();
            });
        }else{
            if (isDisplay == true) {
                isDisplay = "0";
            }else{
                isDisplay = "1";
            }
            $.post("/tencent/fire/saveNotice", {id:id,text: noticeTextArea, isDisplay: isDisplay}, function (data) {
                $('#myModal').modal('hide');
                getNotices();
            });
        }

    }
    function getNotices() {
        $.post("/tencent/fire/getNotice",{},function (data) {
            if(data.code==0){
                var list = data.data;
                var allcontent = "";
                for(var i=0;i<list.length;i++){
                    var content ='<li>'+
                        '                            <div>'+
                        '                                <small onclick="alertModel('+list[i].id+')">'+formatDate(new Date(list[i].createTime))+'</small>'+
                        '                                <h4 onclick="alertModel('+list[i].id+')">后台公告(<span style="color: red">'+type(list[i].isDisplay)+'</span>) </h4>'+
                        '                                <p onclick="alertModel('+list[i].id+')">'+list[i].text+'</p>'+
                        '                                <a onclick="deleteNotice(\''+list[i].id+'\')"><i class="fa fa-trash-o "></i></a>'+
                        '                            </div>'+
                        '                        </li>';
                    allcontent = allcontent + content;
                }
                document.getElementById("notices").innerHTML = allcontent;
            }
        });
    }
    getNotices();
    function deleteNotice(id) {
        $.post("/tencent/fire/deleteNotice?id="+id,function (data) {
                if(data.code==0){
                    getNotices();
                }
        });
    }
</script>
</html>
